#include<iostream>
#include<string>
#include<unistd.h>
#include<fcntl.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main()
{
    string s="./work/systemfile";
    int val=fcntl(atoi(s.c_str()),F_GETFL,0);
    if(!val)
    {
        cout<<"fcntl error"<<endl;
    }
    int accmode=val & O_ACCMODE;

    switch (accmode)
    {
        case O_RDONLY:
            printf("read only\n");
            break;
        case O_WRONLY:
            printf("write only\n");
            break;
        case O_RDWR:
            printf("read write\n");
            break;
        case O_APPEND:
            printf("append\n");
            break;
        default:
            printf("unknow access mode\n");
    }
    
    int fd;
    fd = open("./work/systemfile",O_APPEND);
    
    val=fcntl(atoi(s.c_str()),F_GETFL,0);
    if(!val)
    {
        cout<<"fcntl error"<<endl;
    }
    accmode=val & O_ACCMODE;
    
    close(fd);

    cout<<accmode<<endl;
    return 0;
}
